/*
 * File:    Timer4.c
 * Project:	HobbyPilotFirmware (HPF)
 * Author:  Wouter van Verre
 *
 * Created on February 8, 2011, 11:31 PM
 */

#include "Header.h"


void initTimer4(void)
{
	T4CONbits.TON = 0;		// Turn the Timer2 module off
    T4CONbits.TSIDL = 0;	// Stop when the uC enters idle mode
    T4CONbits.TGATE = 0;	// Disable gated accumulation mode
    T4CONbits.TCKPS = 0b00;	// Set prescaler to 8
    T4CONbits.T32 = 0;		// Disable 32-bit operations
    T4CONbits.TCS = 0;		// Use internal clock as clock source

    PR4 = 8192;          	// ~50Hz (49.98Hz) @ Fcy = 14,74Mhz
	
}

void __attribute__((__interrupt__, __no_auto_psv__)) _T4Interrupt (void)
{
	TMR4 = 0;
	cpuLoadCycles++;

	IFS1bits.T4IF = 0;	// Clear the Timer4 interrupt flag
}
